package hu.tortavar2.client.view.adminpages;

import java.util.List;

import hu.tortavar2.client.view.adminpages._AddShopItemDialog_.AddShopPresenter;
import hu.tortavar2.shared.Shop;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;

public class ManageSiteDataPageImpl extends Composite implements ManageSiteData, AddShopPresenter{

	private static ManageSiteDataPageImplUiBinder uiBinder = GWT
			.create(ManageSiteDataPageImplUiBinder.class);

	interface ManageSiteDataPageImplUiBinder extends
			UiBinder<Widget, ManageSiteDataPageImpl> {
	}

	public ManageSiteDataPageImpl() {
		initWidget(uiBinder.createAndBindUi(this));
		setFields();
	}

	Presenter presenter;
	_AddShopItemDialog_ newShopDialog;
	Anchor addShopAnchor;
	@UiField Anchor addNewShopPopup;
	@UiField HTMLPanel grid_03_left;
	@UiField HTMLPanel grid_03_center;
	@UiField HTMLPanel grid_03_right;
	@UiField HTMLPanel padding_color_left;
	@UiField HTMLPanel padding_color_center;
	@UiField HTMLPanel padding_color_right;
	@UiField HTMLPanel container_left;
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@UiHandler("addNewShopPopup")
	void onClickAddNewShopPopup(ClickEvent e) {
		newShopDialog = new _AddShopItemDialog_(this);
		newShopDialog.show();
	}
	
	private void setFields() {
		grid_03_left.getElement().setClassName("grid_03");
		grid_03_center.getElement().setClassName("grid_03");
		grid_03_right.getElement().setClassName("grid_03");
		padding_color_left.getElement().setClassName("padding pink");
		padding_color_center.getElement().setClassName("padding pink");
		padding_color_right.getElement().setClassName("padding pink");
	}

	@Override
	public void onAddShopButton() {
		// TODO Refaktorálni a neveket, mert ez így szar!
		newShopDialog.hide();
		presenter.onAddNewShop(newShopDialog.getNewShop());
	}

	public void setShops(List<Shop> shops) {
		
		for(Shop shop : shops) {
			container_left.add(new _ShopItem_(shop));
		}
	}
}
